home *** CD-ROM | disk | FTP | other *** search
- /* *********************************************************************************
-
- FILE: Event.c
-
- DESCRIPTION: Event loop called from inside drawMandel at the end of each
- horizontal line. Checks for mouse position, close box, grow box,
- the various combinations of control, apple, shift and option keys
- and menu selects.
-
- AUTHOR: Bruce E. Gladstone
-
- Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
-
- Revision History:
- ============================================================
- 5/1/90 - Release to Compuserve
- ============================================================
-
- COMMENTS:
-
- None.
-
- ******************************************************************************** */
-
- #include <stdio.h>
- #include <MacTypes.h>
- #include <WindowMgr.h>
- #include <MenuMgr.h>
- #include <EventMgr.h>
- #include <ToolboxUtil.h>
- #include <ControlMgr.h>
- #include <color.h>
- #include <colortoolbox.h>
- #include "Mandelbrot.h"
-
-
- /* ---------------------------- Global Variables ---------------------------------- */
-
- extern int colorQD;
- extern int quitFlag;
- extern int linearFlag;
- extern int custPict;
- extern int numColorBits;
- extern int numColors, brushSize;
- extern int limit;
- extern int n;
- extern long startTime, now;
- extern float res;
- extern float centx, centy;
- extern float xmin, xmax, ymin, ymax;
- extern float delx, dely;
-
- /* ---------------------------- Global MacTypes ----------------------------------- */
-
- extern Str255 str;
- extern CTabHandle myColorHandle;
- extern RGBColor aColor;
- extern Rect myRect, dragRect;
- extern WindowPtr aboutWindow;
- extern MenuHandle appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
- extern WindowPtr myWindow;
-
- /* --------------------------- Local Prototypes --------------------------------- */
-
- int eventCheck ( void );
- void doMenu ( long );
-
- /* --------------------------------------------------------------------------------
- eventCheck - 5/01/90 beg
- -------------------------------------------------------------------------------- */
-
- int
- eventCheck ()
- {
- int zIn, zOut;
- char theChar;
- int myPart;
- int result, stillInGoAway;
- EventRecord myEvent;
- WindowPtr whichWindow;
- long windSize;
-
- result = FALSE;
- if ( GetNextEvent ( everyEvent, &myEvent ))
- {
- switch ( myEvent.what )
- {
- case activateEvt:
- case app4Evt:
- if ( colorQD )
- {
- numColorBits = (**(*(CGrafPtr)myWindow).portPixMap).pixelSize;
- numColors = 1 << numColorBits;
- result = TRUE;
- break;
- }
- case keyDown:
- case autoKey:
- if ( ! ( myEvent.modifiers & cmdKey ))
- {
- result = TRUE;
- break;
- }
- if ( myWindow == FrontWindow ())
- {
- theChar = myEvent.message & charCodeMask;
- if ( theChar == 'q' || theChar == 'Q' )
- ExitToShell();
- }
- case mouseDown:
- myPart = FindWindow ( myEvent.where, &whichWindow );
- switch ( myPart )
- {
- case inMenuBar:
- doMenu ( MenuSelect ( myEvent.where ));
- result = TRUE;
- break;
- case inSysWindow:
- SystemClick ( &myEvent, whichWindow );
- if ( colorQD )
- {
- numColorBits = (**(*(CGrafPtr)myWindow).portPixMap).pixelSize;
- numColors = 1 << numColorBits;
- result = TRUE;
- break;
- }
- case inContent:
- if (whichWindow != FrontWindow())
- {
- HiliteWindow ( whichWindow, TRUE );
- }
- else if ( whichWindow == myWindow )
- {
- zIn = ( myEvent.modifiers & cmdKey );
- zOut = ( myEvent.modifiers & optionKey );
- if ( zOut != 0 && zIn == 0 )
- {
- res = res*2;
- }
- if ( zIn != 0 && zOut == 0 )
- {
- switch ( custPict )
- {
- case 1:
- centx = -0.55;
- centy = 0.60;
- res = 0.10;
- custPict = 2;
- break;
- case 2:
- centx = -0.92;
- centy = 0.26;
- res = 0.03;
- custPict = 3;
- break;
- case 3:
- centx = -1.253;
- centy = 0.046;
- res = 0.001;
- custPict = 4;
- break;
- case 4:
- centx = -1.25316;
- centy = 0.0465;
- res = 0.0005;
- custPict = 5;
- break;
- case 5:
- centx = -0.747;
- centy = 0.106;
- res = 0.001;
- custPict = 6;
- break;
- case 6:
- centx = -0.74543;
- centy = 0.11301;
- res = 0.00001;
- custPict = 1;
- break;
- }
- result = TRUE;
- break;
- }
- if ( zIn != 0 && zOut != 0 )
- {
- centx = -0.8;
- centy = 0.0;
- res = 1.0;
- result = TRUE;
- break;
- }
- if ( myEvent.modifiers & shiftKey )
- {
- res = 0.5*res;
- }
-
- GlobalToLocal ( &myEvent.where );
- centx = xmin + delx * ( myEvent.where.h );
- centy = ymin + delx * ( myEvent.where.v );
- result = TRUE;
- break;
- }
- case inDrag:
- DragWindow ( whichWindow, myEvent.where, &dragRect );
- result = TRUE;
- break;
- case inGrow:
- windSize = GrowWindow ( whichWindow, myEvent.where, &dragRect );
- SizeWindow ( whichWindow, LoWord ( windSize ), HiWord
- ( windSize ), TRUE );
- myRect = (*myWindow).portRect;
- ClipRect ( &myRect );
- FillRect ( &myRect, white );
- result = TRUE;
- break;
- case inGoAway:
- stillInGoAway = TrackGoAway ( whichWindow, myEvent.where );
- if ( stillInGoAway )
- {
- CloseWindow ( whichWindow );
- ExitToShell();
- }
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox ( whichWindow, myEvent.where, myPart ))
- {
- ZoomWindow ( whichWindow, myPart, FALSE );
- myRect = (*myWindow).portRect;
- ClipRect ( &myRect );
- FillRect ( &myRect, white );
- result = TRUE;
- break;
- }
- }
- default:
- return ( result );
- }
- }
- return ( result );
- } /* eventCheck () */
-
- /* =============================== EOF ==========================================
- Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
- ================================================================================ */
-
-